qsort() from <stdlib.h>

An ANSI C Generic Algorithm

void qsort( void *base, size_t nmemb, size_t size, int(*compare)(const void *, const void *)); where: base is a pointer to an array nmemb is the number of elements in the array size is the size of each array element compare is a pointer to a function defined as: int compare(const void *e1, const void *e2); where: e1 and e2 are elements pointers returns if < 0 (*e1) < (*e2) 0 (*e1) == (*e2) > 0 (*e1) > (*e2) When subtraction is a valid operations for elements of type T, the compare funtion can be implemented as: { return (int)((*(T *)e1) - (*(T *)e2)); }